package com.walker.jdkapi.future;

import org.springframework.util.ObjectUtils;

public class ProxyData implements Data {
	
	private TargetData targetData;
	
	private boolean isReady = false;

	@Override
	public synchronized String getRequest() {
		while(!isReady && ObjectUtils.isEmpty(targetData)) {
			try {
				//如果真实数据还未加载成功，等待
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return this.targetData.getRequest();
	}

	public synchronized void setTargetData(TargetData targetData) {
		//如果目标对象已经设置，不在执行该方法
		while(isReady && !ObjectUtils.isEmpty(targetData)) {
			return;
		}
		this.targetData = targetData;
		isReady = true;
		this.notify();
	}
	
	

}
